#ifndef _BOUNDINGBOX_H
#define _BOUNDINGBOX_H

#include "vector2.h"

class BoundingBox
{
public:

	BoundingBox()
	{
		spriteWidthHalf = 0;
		spriteHeightHalf = 0;
		left = -1;
		top = -1;
		right = -1;
		bottom = -1;
	}

	BoundingBox(Vector2 position, int spriteWidth, int spriteHeight)
	{
		spriteWidthHalf = (float)spriteWidth / 2;
		spriteHeightHalf = (float)spriteHeight / 2;
		left = position.x - spriteWidthHalf;
		top = position.y + spriteHeightHalf;
		right = position.x + spriteWidthHalf;
		bottom = position.y - spriteHeightHalf;
	}

	BoundingBox(Vector2 position, float spriteWidth, float spriteHeight)
	{
		spriteWidthHalf = spriteWidth / 2;
		spriteHeightHalf = spriteHeight / 2;
		left = position.x - spriteWidthHalf;
		top = position.y + spriteHeightHalf;
		right = position.x + spriteWidthHalf;
		bottom = position.y - spriteHeightHalf;
	}

	bool Intersects(BoundingBox bb)
	{
		if(top < bb.bottom)
		{
			return false;
		}
		else if(bottom > bb.top)
		{
			return false;
		}
		else if(left > bb.right)
		{
			return false;
		}
		else if(right < bb.left)
		{
			return false;
		}
		return true;
	}

	bool Intersects(Vector2 point)
	{
		if(top < point.y)
		{
			return false;
		}
		else if(bottom > point.y)
		{
			return false;
		}
		else if(left > point.x)
		{
			return false;
		}
		else if(right < point.x)
		{
			return false;
		}
		return true;
	}

	void UpdatePosition(Vector2 position)
	{
		left = position.x - spriteWidthHalf;
		top = position.y + spriteHeightHalf;
		right = position.x + spriteWidthHalf;
		bottom = position.y - spriteHeightHalf;
	}

private:
	float spriteWidthHalf;
	float spriteHeightHalf;
	float top;
	float left;
	float bottom;
	float right;
};

#endif
